package com.maxchaintech.integral.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maxchaintech.integral.domain.PointsRedemptionOrderDetails;
import com.maxchaintech.integral.service.IPointsRedemptionOrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.maxchaintech.common.log.annotation.Log;
import com.maxchaintech.common.log.enums.BusinessType;
import com.maxchaintech.common.security.annotation.PreAuthorize;
import com.maxchaintech.common.core.web.controller.BaseController;
import com.maxchaintech.common.core.web.domain.AjaxResult;
import com.maxchaintech.common.core.utils.poi.ExcelUtil;
import com.maxchaintech.common.core.web.page.TableDataInfo;

/**
 * 积分兑换订单详情Controller
 * 
 * @author jyw
 * @date 2021-04-20
 */
@RestController
@RequestMapping("/details")
public class PointsRedemptionOrderDetailsController extends BaseController
{
    @Autowired
    private IPointsRedemptionOrderDetailsService pointsRedemptionOrderDetailsService;

    /**
     * 查询积分兑换订单详情列表
     */
    @PreAuthorize(hasPermi = "integral:details:list")
    @GetMapping("/list")
    public TableDataInfo list(PointsRedemptionOrderDetails pointsRedemptionOrderDetails)
    {
        startPage();
        List<PointsRedemptionOrderDetails> list = pointsRedemptionOrderDetailsService.selectPointsRedemptionOrderDetailsList(pointsRedemptionOrderDetails);
        return getDataTable(list);
    }

    /**
     * 导出积分兑换订单详情列表
     */
    @PreAuthorize(hasPermi = "integral:details:export")
    @Log(title = "积分兑换订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsRedemptionOrderDetails pointsRedemptionOrderDetails) throws IOException
    {
        List<PointsRedemptionOrderDetails> list = pointsRedemptionOrderDetailsService.selectPointsRedemptionOrderDetailsList(pointsRedemptionOrderDetails);
        ExcelUtil<PointsRedemptionOrderDetails> util = new ExcelUtil<PointsRedemptionOrderDetails>(PointsRedemptionOrderDetails.class);
        util.exportExcel(response, list, "积分兑换订单详情数据");
    }

    /**
     * 获取积分兑换订单详情详细信息
     */
    @PreAuthorize(hasPermi = "integral:details:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pointsRedemptionOrderDetailsService.selectPointsRedemptionOrderDetailsById(id));
    }

    /**
     * 新增积分兑换订单详情
     */
    @PreAuthorize(hasPermi = "integral:details:add")
    @Log(title = "积分兑换订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsRedemptionOrderDetails pointsRedemptionOrderDetails)
    {
        return toAjax(pointsRedemptionOrderDetailsService.insertPointsRedemptionOrderDetails(pointsRedemptionOrderDetails));
    }

    /**
     * 修改积分兑换订单详情
     */
    @PreAuthorize(hasPermi = "integral:details:edit")
    @Log(title = "积分兑换订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsRedemptionOrderDetails pointsRedemptionOrderDetails)
    {
        return toAjax(pointsRedemptionOrderDetailsService.updatePointsRedemptionOrderDetails(pointsRedemptionOrderDetails));
    }

    /**
     * 删除积分兑换订单详情
     */
    @PreAuthorize(hasPermi = "integral:details:remove")
    @Log(title = "积分兑换订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsRedemptionOrderDetailsService.deletePointsRedemptionOrderDetailsByIds(ids));
    }
}
